package ipad.asia.dao;

import ipad.asia.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Repository
public interface OrderDao extends JpaRepository<Order,Long> {
     /**
      * 订单状态：0创建为支付，1已经付，2已发货，3已收货，4已退款，5已完成
      */
     /***
      * @param shopId
      * @商家
      */
     //商家的所有订单
     List<Order> findByShopId(int shopId);
     //查看商家取消订单
     List<Order> findByShopCancel(int shopId);
     //商家按产品id查找商品订单
     List<Order> findByProductIdAndShopId(int productId,int shopId);
     //查找商家订单状态
     List<Order> findByStatuesAndShopId(int statues,int shopId);
     //商家按照日期查找支付订单
     List<Order> findByPayDateBetweenAndShopId(LocalDateTime timeDown,LocalDateTime timeUp,int shopId);
     //商家删除订单
     void deleteByIdAndShopId(int id,int shopId);
     //商家取消的订单
     /**
      * @param consumerId
      * @顾客
      */
     //顾客所有订单
     List<Order> findByConsumerId(int consumerId);
     //顾客查找取消的订单
     List<Order> findByConsumerCancel(int consumerId);
     //顾客查找商品的订单
     List<Order> findByProductIdAndConsumerId(int productId,int consumerId);
     //顾客查找订单状态的订单
     List<Order> findByStatuesAndConsumerId(int statues,int consumerId);
     //顾客按照日期查找的订单
     List<Order> findByPayDateBetweenAndConsumerId(LocalDateTime timeDown,LocalDateTime timeUp,int consumerId);

     void deleteByIdAndConsumerId(int id,int consumerId);


     Order findById(int id);  //搜索产品的订单
     List<Order> findByStatues(int statues);  //查看订单状态
     List<Order> findAll();  //查找全部订单
     @Modifying
     @Query("update Order set statues=?2 where id=?1")
     void updateStatue(int id,int statues);
     @Modifying
     @Query("update Order set statues=?2,payDate=?3 where id=?1")
     void updatePayStatue(int id, int statues, Date payDate);
     void deleteById(int id);

     List<Order> findByShopIdAndStatues(int shopId,int statues);
     List<Order> findByShopIdAndIdAndStatues(int shopId,int id,int statues);
}
